﻿{include file='pub/header'/}
<title>优惠券列表</title>
</head>
<body>
<nav class="breadcrumb">{$breadNav} <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l">
			<a href="javascript:;" onclick="active_add('添加优惠券','{:url(\'Marketing/coupon_add\')}','800','500')" class="btn btn-primary radius">
				<i class="Hui-iconfont">&#xe600;</i> 添加优惠券
			</a>
		</span>
	</div>
	<table class="table table-border table-bordered table-bg">
		<thead>
			<tr>
				<th scope="col" colspan="9">优惠券列表</th>
			</tr>
			<tr class="text-c">
				<th width="40">ID</th>
				<th width="150">优惠券名称</th>
				<th width="150">优惠券金额</th>
				<th width="150">最低消费额</th>
				<th width="150">优惠券类型</th>
				<th width="150">开始时间</th>
				<th width="150">结束时间</th>
				<th width="120">操作</th>
			</tr>
		</thead>
		<tbody>
		{foreach $list as $v}
			<tr class="text-c">
				<td>{$v.id}</td>
				<td>{$v.name}</td>
				<td>{$v.cost}</td>
				<td>{$v.min_cost}</td>
				<td>{$cat[$v.type]}</td>
				<td>{$v.start_time}</td>
				<td>{$v.end_time}</td>
				<td class="td-manage">
					<a title="编辑" href="javascript:;" onclick="active_edit('编辑优惠券','{:url(\'Marketing/coupon_edit\', [\'id\'=>$v.id])}','800','500')" class="ml-5" style="text-decoration:none">
						<i class="Hui-iconfont">&#xe6e2;</i>编辑
					</a>
					<a title="删除" href="javascript:;" onclick="active_del(this,'{$v.id}')" class="ml-5" style="text-decoration:none">
						<i class="Hui-iconfont">&#xe6e2;</i>删除
					</a>
				</td>
			</tr>
		{/foreach}
		</tbody>
	</table>
</div>
{include file="pub/footer"/}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
/*管理员-增加*/
function active_add(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-删除*/
function active_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '{:url("Marketing/active_del")}',
			data:{id:id},
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}

/*管理员-编辑*/
function active_edit(title,url,w,h){
	layer_show(title,url,w,h);
}
/*管理员-停用*/
function active_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		$.post("{:url('Marketing/changeStatus')}", {id:id, status:0}, function(res){
		    if(res.code == 1){
                $(obj).parents("tr").find(".td-manage").prepend('<a onClick="active_start(this,'+id+')" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;启用</i></a>');
                $(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
                $(obj).remove();
                layer.msg('已停用!',{icon: 5,time:1000});
            }else{
		        layer.msg(res.msg);
			}
        });
	});
}

/*管理员-启用*/
function active_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		$.post("{:url('Marketing/changeStatus')}", {id:id, status:1}, function(res){
			if(res.code == 1){
                $(obj).parents("tr").find(".td-manage").prepend('<a onClick="active_stop(this,'+id+')" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;停用</i></a>');
                $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
                $(obj).remove();
                layer.msg('已启用!', {icon: 6,time:1000});
            }else{
			    layer.msg(res.msg);
			}
        });
	});
}
</script>
</body>
</html>